import * as cws from '../lib/net/client-websocket';
import * as wsEvent from '../lib/net/event-websocket';
import * as protobuf from '../lib/protobuf/protobuf-msg';

console.log("websocket-test");
export let classList = protobuf.getMsgProto();  

export function main(){

    let client = new cws.ClientWebSocket();
    let host = "127.0.0.1";
    let port = 4000;
    client.Connection(host,port);
    console.log("connection ",new Date().getTime());
    client.on(wsEvent.Event.open,()=>{
        // let classList = protobuf.getMsgProto();       
        // let newClass = new classList.login_login_c2s();
        // newClass.user_pass = "1111";
        // newClass.user_name = new Date().getTime().toString();
        // let base = new classList.msg_base_c2s();
        // base.setMsg(newClass.toArrayBuffer() as any);
        // base.msg_code = protoBufMsg.head.msg_login_login_c2s;
        // base.msg_type = 1;//Math.max(1,Math.floor(Math.random()*5));
        // console.log("open ",new Date().getTime(),base.msg_type);
        // client.send(msgList[10000].toArrayBuffer());
        client.getClient().ping();
    });
    client.on(wsEvent.Event.clientMessage,(msg)=>{
        console.log("message ",new Date().getTime(),msg);
    });
}
main();

export function c2s(head:number,newClass,serverType=1){
    let base = new classList.msg_base_c2s();
    base.setMsg(newClass.toArrayBuffer() as any);
    base.msg_code = head;
    base.msg_type = serverType;
}
 
export let msgList:any={
    10000:function(){ 
        let newClass = new classList.login_login_c2s();
        newClass.user_pass = "1111";
        newClass.user_name = new Date().getTime().toString();

    },
    10002:function(){
        let newClass = new classList.login_login_c2s();
        newClass.user_pass = "1111";
        newClass.user_name = new Date().getTime().toString();

    },
};
export function send_100001(){

}